package cn.stylefeng.guns.modular.score.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.score.entity.ScoreInfo;
import cn.stylefeng.guns.modular.score.mapper.ScoreInfoMapper;
import cn.stylefeng.guns.modular.score.model.params.ScoreInfoParam;
import cn.stylefeng.guns.modular.score.model.result.ScoreInfoResult;
import  cn.stylefeng.guns.modular.score.service.ScoreInfoService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 排名表 服务实现类
 * </p>
 *
 * @author dong
 * @since 2023-04-21
 */
@Service
public class ScoreInfoServiceImpl extends ServiceImpl<ScoreInfoMapper, ScoreInfo> implements ScoreInfoService {

    @Override
    public void add(ScoreInfoParam param){
        ScoreInfo entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ScoreInfoParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ScoreInfoParam param){
        ScoreInfo oldEntity = getOldEntity(param);
        ScoreInfo newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ScoreInfoResult findBySpec(ScoreInfoParam param){
        return null;
    }

    @Override
    public List<ScoreInfoResult> findListBySpec(ScoreInfoParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ScoreInfoParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ScoreInfoParam param){
        return param.getScoreId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ScoreInfo getOldEntity(ScoreInfoParam param) {
        return this.getById(getKey(param));
    }

    private ScoreInfo getEntity(ScoreInfoParam param) {
        ScoreInfo entity = new ScoreInfo();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<Map<String, Object>> getPmList() {
		return this.baseMapper.getPmList();
	}

    @Override
    public Integer getTaskNum(Integer teamId) {
        return this.baseMapper.getTaskNum(teamId);
    }

}
